package com.girl.girl.exception;

import com.girl.girl.Utils.ResultUtil;
import com.girl.girl.domain.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by qxl on
 * 2018/7/3
 */
public class ExceptionHandle {

    private final static Logger logger
            = LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e){
        if (e instanceof GilrException){
            GilrException girlException = (GilrException) e;
            return ResultUtil.error(girlException.getCode(), girlException.getMsg());
        }else{
            logger.error("【系统异常】{}", e);
            return ResultUtil.error(-1, "未知错误");
        }
    }
}
